package CreationMode.prototype.DeedClone.demo1;

import java.io.*;

public class Realizetype implements Cloneable,Serializable{

    public String name;

    public Realizetype(String name) {
        System.out.println("构造了一个对象");
        this.name = name;
    }

    public Realizetype() {
        System.out.println("构造了一个对象");
    }

    @Override
    protected Realizetype clone() throws CloneNotSupportedException {
        Realizetype realizetype = null;

        ByteArrayOutputStream baos =new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);
            oos.close();
            baos.close();
        }catch (IOException e){
            e.printStackTrace();
        }

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        try {
            ObjectInputStream ois = new ObjectInputStream(bais);
            realizetype = (Realizetype) ois.readObject();
            ois.close();
            bais.close();

        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }

        return realizetype;
    }
}
